package com.shiyi.design.singleton;

/**
 * 饿汉式
 * 直接将实例定义为静态常量，在类加载的时候，初始化阶段，进行实例化，由JVM保证单例
 * 但是因为类装载就实例化了，浪费内存空间
 * @Author qiu
 * @Date 2021/1/10 23:09
 */
public class SingletonDesignModel1 {
    private static final SingletonDesignModel1 INSTANCE = new SingletonDesignModel1();

    private SingletonDesignModel1(){};

    public static SingletonDesignModel1 getInstance() {
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(getInstance().hashCode())).start();
        }
    }
}
